Imports System.Web
Imports System.Web.Profile
Imports Microsoft.VisualBasic
Imports System.Web.Security
Imports System.Web.UI
Imports System.Text.RegularExpressions
Imports System.Text
Imports System.Web.UI.HtmlControls
Imports System.Web.Configuration
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Collections
Imports ADOEntityImportData
'Imports TheBeerHouse.BLL

Namespace Web.UI

    Public Class BasePage
        Inherits System.Web.UI.Page

        Public Enum statusbtn
            Query = 1
            Add = 2
            Modify = 3
            delete = 4
            print = 5
            Modify1 = 6
        End Enum
      
        Public Sub SetLinkManual()
            Dim link As HyperLink = CType(Master.FindControl("linkManual"), HyperLink)

            Dim path As String = System.Configuration.ConfigurationManager.AppSettings("Path_DOC_MANUAL")
            Dim url As String = Me.Request.RawUrl.Replace(BaseUrl, "")
            Dim importDataEntity = New ImportDataEntity()

            Dim fileName = (From doc In importDataEntity.KYC_USER_MANUAL Where doc.URL = url Select doc.FILE_NAME).ToList
            If (fileName.Count > 0) Then
                link.NavigateUrl = System.IO.Path.Combine(path, fileName(0))
                link.Visible = True
            Else
                link.Visible = False
            End If
        End Sub


        Public Sub setBtnToUserRight(ByRef coll As Collection, ByVal strPgCode As String, _
                                     ByVal ds As dataset)
            Dim bt As Button = Nothing
            Dim intCount As Integer = 0
            Dim dr As DataRow() = ds.Tables("sMenuRight").Select("ProgramCode = '" & strPgCode & "'")
            If (dr(0)("ISSHOW")) Then
                intCount = coll.Count
                If (coll.Contains(statusbtn.Query.ToString)) Then
                    bt = coll(statusbtn.Query.ToString)
                    If Not (dr(0)("MQUERY") Is DBNull.Value) Then
                        If (dr(0)("MQUERY")) Then
                            bt.Visible = True
                        Else
                            bt.Visible = False
                        End If
                    Else
                        bt.Visible = False
                    End If

                End If

                If (coll.Contains(statusbtn.Add.ToString)) Then
                    bt = coll(statusbtn.Add.ToString)
                    If Not (dr(0)("MADD") Is DBNull.Value) Then
                        If (dr(0)("MADD")) Then
                            bt.Visible = True
                        Else
                            bt.Visible = False
                        End If
                    Else
                        bt.Visible = False
                    End If

                End If

                If (coll.Contains(statusbtn.Modify.ToString)) Then
                    bt = coll(statusbtn.Modify.ToString)
                    If Not (dr(0)("MMODIFY") Is DBNull.Value) Then
                        If (dr(0)("MMODIFY")) Then
                            bt.Visible = True
                        Else
                            bt.Visible = False
                        End If
                    Else
                        bt.Visible = False
                    End If

                End If

                If (coll.Contains(statusbtn.Modify1.ToString)) Then
                    bt = coll(statusbtn.Modify1.ToString)
                    If Not (dr(0)("MMODIFY") Is DBNull.Value) Then
                        If (dr(0)("MMODIFY")) Then
                            bt.Visible = True
                        Else
                            bt.Visible = False
                        End If
                    Else
                        bt.Visible = False
                    End If

                End If

                If (coll.Contains(statusbtn.delete.ToString)) Then
                    bt = coll(statusbtn.delete.ToString)
                    If Not (dr(0)("MDELETE") Is DBNull.Value) Then
                        If (dr(0)("MDELETE")) Then
                            bt.Visible = True
                        Else
                            bt.Visible = False
                        End If
                    Else
                        bt.Visible = False
                    End If

                End If

                

                If (coll.Contains(statusbtn.print.ToString)) Then
                    bt = coll(statusbtn.print.ToString)
                    If Not (dr(0)("MPRINT") Is DBNull.Value) Then
                        If (dr(0)("MPRINT")) Then
                            bt.Visible = True
                        Else
                            bt.Visible = False
                        End If
                    Else
                        bt.Visible = False
                    End If

                End If

            Else
                Me.Response.Redirect("~/KYC/News.aspx")
            End If
           


        End Sub


        Public Sub RequestLogin()
            Me.Response.Redirect("~/KYC/index.aspx")
        End Sub

        Public Sub chkIsLogin()
            If Session("ClsMenuRight") Is Nothing Then
                Me.Response.Redirect("../KYC/index.aspx?SessionOut=1")
            End If
        End Sub

        Public ReadOnly Property BaseUrl() As String
            Get
                Dim url As String = Me.Request.ApplicationPath
                If url.EndsWith("/") Then
                    Return url
                Else
                    Return url + "/"
                End If
            End Get
        End Property

        Public ReadOnly Property FullBaseUrl() As String
            Get
                Return Me.Request.Url.AbsoluteUri.Replace( _
                    Me.Request.Url.PathAndQuery, "") + Me.BaseUrl
            End Get
        End Property




        Public ReadOnly Property UserName() As String
            Get
                Return HttpContext.Current.User.Identity.Name
            End Get
        End Property

        Protected Overloads Overrides Sub OnLoad(ByVal e As EventArgs)
            ' add onfocus and onblur javascripts to all input controls on the forum, 
            ' so that the active control has a difference appearance 
            'Helpers.SetInputControlsHighlight(Me, "highlight", False)

            MyBase.OnLoad(e)
        End Sub

        Protected Sub SetDateTextBoxValue(ByVal vTextBox As TextBox, ByVal vDate As DateTime)
            If vDate = DateTime.MinValue Then
                vTextBox.Text = String.Empty
            Else
                vTextBox.Text = vDate.ToShortDateString
            End If
        End Sub

        Protected Sub GetDateTextBoxValue(ByVal vTextBox As TextBox, ByRef vDate As DateTime?)
            If String.IsNullOrEmpty(vTextBox.Text) Then
                vDate = DateTime.MinValue
            Else
                vDate = vTextBox.Text
            End If
        End Sub

        Public Sub WriteError(ByVal objEx As Exception, ByVal strFunctionName As String, ByVal strFromName As String)
            Try
                Dim clsSessionMenuRight As clsSessionMenuRight = Session("clsMenuRight")
                Dim cls As New clsWriteError
                cls.GetstrErrorMessage = objEx.Message
                cls.GetstrErrorException = If(objEx.InnerException Is Nothing, "", objEx.InnerException.Message)
                cls.GetstrFromName = strFromName
                cls.GetstrUserName = clsSessionMenuRight.getUserName
                cls.GetstrUserRight = clsSessionMenuRight.getUserRight
                cls.GetstrFunctionName = strFunctionName
                cls.CreateFileXml(clsSessionMenuRight.getBranchCode)

                clsSessionMenuRight = Nothing
                cls = Nothing
            Catch ex As Exception

            End Try

        End Sub



    End Class

End Namespace
